#include <fstream>
#include <omp.h>
#include <string.h>

#include "Matrix.hpp"

using std::cout;
using std::ofstream;

void generateMatrix( int size, const char* filename )
{
  
  Matrix newMatrix = Matrix::generate( size ); 
  
  ofstream out( filename );
  
  newMatrix.print( out );
  
}

int main( int argc, char **argv )
{
  
  if( argc < 2 )
    return 0;
 
  if( strcmp( argv[ 1 ], "--generate" ) == 0 )
  {
    int size = 1000;
    if( argc > 2 )
      sscanf( argv[ 2 ], "%d", &size );
    
    if( argc > 3 )
      generateMatrix( size, argv[ 3 ] );
    else 
      generateMatrix( size, "matrix" );
    
    return 0;
    
  }
 
  Matrix matrix = Matrix::load( argv[ 1 ] );
  
  Matrix lMatrix = Matrix::generateIdentity( matrix.N() );
  Matrix uMatrix = matrix.copy();
  
  double startTime = omp_get_wtime();
  uMatrix.doLUBlock( lMatrix );
  double endTime = omp_get_wtime();
  
  cout << "Time: " << endTime-startTime << std::endl;
  
  return 0;
  
}